package com.bdqn.day0919.service.impl;

import com.bdqn.day0919.entity.User;
import com.bdqn.day0919.mapper.UserMapper;
import com.bdqn.day0919.service.UserService;
//import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:Corday
 * @Date:2021/09/19/9:35
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    //@Autowired(required = false)
    private UserMapper um;

    @Override
    public Integer saveUser(User user) {
        Integer temp = um.insertUser(user);
        return temp;
    }

    @Override////////添加多条记录
    public String saveUsers(List<User> users) {
        Integer temp = um.insertUsers(users);
        return temp==null?"添加失败":"增加成功"+temp;
    }

    @Override
    public String removeUser(Integer uid) {
        Integer temp=um.deleteUser(uid);
        return temp==null?"操作失败":"删除成功";
    }

    @Override
    public String changeUser(Integer uid,User user) {
        String sex = user.getSex();
        Integer temp=um.updateUser(uid,sex);
        return temp==null?"更新失败":"修改成功";
    }

    @Override
    public List<User> findUsers() {
        //将工号为10086的员工的姓名改为小帅，并写入集合对象
        um.updateUser(10001,"小帅");
        return um.selectUsers();
    }
}
